/**
 * AreaFoto.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.presentacion;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;


public class AreaFoto extends javax.swing.JPanel {

    private BufferedImage imagen;
    private Color color = new Color(128, 128, 255);
    private int tamaño = 5;
    private Image imagenDefault;
    /** Creates new form AreaFoto */
    public AreaFoto() {
        initComponents();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adsec.presentacion.LiceoEscazuApp.class).getContext().getResourceMap(AreaFoto.class);
        imagenDefault = resourceMap.getImageIcon("imagenDefault").getImage();

    }

    @Override
    public void paint(Graphics g){
        super.paint(g);
        if(imagen != null){
            g.drawImage(imagen, tamaño, tamaño, this.getWidth()-tamaño*2, this.getHeight()-tamaño*2,color, null);
        }else{
            g.setColor(color);
            g.drawImage(this.imagenDefault, tamaño, tamaño, this.getWidth()-tamaño*2, this.getHeight()-tamaño*2,color, null);
        }
    }

    public void mostrarImagen(InputStream imagenFlujo){
        try{
            if(imagenFlujo != null){
                imagen = ImageIO.read(imagenFlujo);   
            }else{
                imagen = null;
            }
            this.repaint();
        }catch(IOException e){
            e.printStackTrace();
        }
    }

    public void limpiarFoto(){
        this.imagen = null;
        this.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setMaximumSize(new java.awt.Dimension(100, 120));
        setMinimumSize(new java.awt.Dimension(100, 120));
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 120, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
